package com.cy.pj.sys.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.common.web.pojo.JsonResult;
import com.cy.pj.sys.pojo.CGBMenu;
import com.cy.pj.sys.service.CGBMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menu/")
public class CGBMenuController {
    @Autowired
    private CGBMenuService cgbMenuService;

    @PutMapping
    public JsonResult doUpdateMenu(@RequestBody CGBMenu cgbMenu){
        cgbMenuService.updateMenu(cgbMenu);
        return new JsonResult("update ok");
    }
    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(cgbMenuService.findById(id));
    }
    @PostMapping
    public JsonResult doSaveMenu(@RequestBody CGBMenu cgbMenu){
       cgbMenuService.saveMenu(cgbMenu);
       return  new JsonResult("save ok");
    }
    @GetMapping
    public JsonResult doFindMenus(){
        return new JsonResult(PageUtil.startPage().doSelectPageInfo(()->cgbMenuService.selectMenus()));
    }

}
